'use strict';
const {
  getValue,
  TDZ,
  BindingBlock_loop,
  BindingBlock_FunctionsInLoops,
} = require('../src/varDeclarationsandHoisting.js');

var assert = require('assert');
require('mocha-sinon');

describe('var Declarations and Hoisting', function () {
  afterEach(function () {});
  beforeEach(function() {
    this.sinon.stub(console, 'log');
  });

  it('should getValue', function (done) {
    let ret = getValue(true);
    assert.strictEqual(ret, 'blue');

    ret = getValue(false);
    assert.strictEqual(ret, null);
    done();
  });

  it('should TDZ', function (done) {
    let ret = TDZ(true);
    assert.strictEqual(ret, true);
    done();
  });

  it('should BindingBlock_loop', function (done) {
    let ret = BindingBlock_loop();
    assert.strictEqual(ret, null);
    done();
  });

  it('should BindingBlock_FunctionsInLoops', function (done) {
    let funcs = BindingBlock_FunctionsInLoops();
    
    for(let i = 0; i < funcs.length; i++){
      funcs[i]();
      assert.strictEqual(console.log.calledWith(i), true);
    }
    done();
  });
  
  
});
